using System;
using System.Data;
using System.Collections.Generic;
using ADOBase;
namespace eTMS.DAO{
	/********************************BEGIN TinhThanhDAO****************************************/
	///<summary>
	/// <para>Author: Auto generated class by CSharp Code Generator v2.0</para>
	/// <para>Date:26/10/2011 34:05:09</para>
	/// <para>Class Name: TinhThanhDAO</para>
	/// <para>Description: Class access to table TinhThanh in database. Coder should'nt code here.</para>
	///</summary>

	
	public partial class TinhThanhDAO : DAOBase<TinhThanhEntity>{


		#region Select functions
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: CreateSelectOneCommand</para>
		/// <para>Input: TinhThanh_ID</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateSelectOneCommand(int TinhThanh_ID){
			string strSQL="SELECT  [TinhThanh_ID],[MaTinhThanh],[TenTinhThanh],[GhiChu],[QuocGia_ID] FROM [TinhThanh]  WHERE [TinhThanh].[TinhThanh_ID]=@TinhThanh_ID";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@TinhThanh_ID",TinhThanh_ID);



			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: SelectOne</para>
		/// <para>Input: TinhThanh_ID</para>
		/// <para>Output: TinhThanhEntity</para>
		///</summary>
		public TinhThanhEntity SelectOne(int TinhThanh_ID){
			IDbCommand cmd=this.CreateSelectOneCommand(TinhThanh_ID);
			return this.Select(cmd);
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: SelectOneByMaTinhThanh</para>
		/// <para>Input: MaTinhThanh</para>
		/// <para>Output: TinhThanhEntity</para>
		///</summary>
		public TinhThanhEntity SelectOneByMaTinhThanh(string MaTinhThanh){
			IDbCommand cmd=this.CreateSelectAllByKeyCommand("MaTinhThanh",MaTinhThanh);
			return this.Select(cmd);
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: CreateSelectAllCommand</para>
		/// <para>Input: </para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateSelectAllCommand(){
			string strSQL="SELECT  [TinhThanh_ID],[MaTinhThanh],[TenTinhThanh],[GhiChu],[QuocGia_ID] FROM [TinhThanh] ";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: CreateSelectAllByKeyCommand</para>
		/// <para>Input: ColumnName,ColumnValue</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateSelectAllByKeyCommand(string ColumnName,object Value){
			string strSQL="SELECT  [TinhThanh_ID],[MaTinhThanh],[TenTinhThanh],[GhiChu],[QuocGia_ID] FROM [TinhThanh]  WHERE [TinhThanh].["+ColumnName+"]=@ColumnName";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@ColumnName",Value);



			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: SelectAll</para>
		/// <para>Input: </para>
		/// <para>Output: List of TinhThanhEntity</para>
		///</summary>
		public List<TinhThanhEntity> SelectAll(){
			IDbCommand cmd=this.CreateSelectAllCommand();
			return this.SelectList(cmd);
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: SelectAllDS</para>
		/// <para>Input: </para>
		/// <para>Output: DataSet</para>
		///</summary>
		public DataSet SelectAllDS(){
			IDbCommand cmd=this.CreateSelectAllCommand();
			return this.SelectDS(cmd);
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: CreateSelectAllFilterCommand</para>
		/// <para>Input: </para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateSelectAllFilterCommand(string strFilter){
			string strSQL="SELECT  [TinhThanh_ID],[MaTinhThanh],[TenTinhThanh],[GhiChu],[QuocGia_ID] FROM [TinhThanh]  WHERE "+RemoveInjection(strFilter);
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: CreateSelectAllByKeyFilterCommand</para>
		/// <para>Input: ColumnName,ColumnValue</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateSelectAllByKeyFilterCommand(string strFilter,string ColumnName,object Value){
			string strSQL="SELECT  [TinhThanh_ID],[MaTinhThanh],[TenTinhThanh],[GhiChu],[QuocGia_ID] FROM [TinhThanh]  WHERE [TinhThanh].["+ColumnName+"]=@ColumnName AND "+RemoveInjection(strFilter);
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@ColumnName",Value);



			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: SelectAll</para>
		/// <para>Input: </para>
		/// <para>Output: List of TinhThanhEntity</para>
		///</summary>
		public List<TinhThanhEntity> SelectAllFilter(string strFilter){
			IDbCommand cmd=this.CreateSelectAllFilterCommand(strFilter);
			return this.SelectList(cmd);
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: SelectAllDSFilter</para>
		/// <para>Input: </para>
		/// <para>Output: DataSet</para>
		///</summary>
		public DataSet SelectAllDSFilter(string strFilter){
			IDbCommand cmd=this.CreateSelectAllFilterCommand(strFilter);
			return this.SelectDS(cmd);
		}
		#endregion

		#region Insert functions
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: CreateInsertCommand</para>
		/// <para>Input: TinhThanhEntity</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateInsertCommand(TinhThanhEntity o){
			string strSQL="INSERT INTO [TinhThanh]([MaTinhThanh],[TenTinhThanh],[GhiChu],[QuocGia_ID]) VALUES  (@MaTinhThanh,@TenTinhThanh,@GhiChu,@QuocGia_ID);SELECT  @@IDENTITY";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			if(o.IsNullMaTinhThanh)
				this.CreateCommandParameter(cmd,"@MaTinhThanh",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@MaTinhThanh",o.MaTinhThanh);

			if(o.IsNullTenTinhThanh)
				this.CreateCommandParameter(cmd,"@TenTinhThanh",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@TenTinhThanh",o.TenTinhThanh);

			if(o.IsNullGhiChu)
				this.CreateCommandParameter(cmd,"@GhiChu",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@GhiChu",o.GhiChu);

			if(o.IsNullQuocGia_ID)
				this.CreateCommandParameter(cmd,"@QuocGia_ID",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@QuocGia_ID",o.QuocGia_ID);


			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: Save</para>
		/// <para>Input: TinhThanhEntity</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool Save(TinhThanhEntity o){
			bool result=false;
			IDbCommand cmd=this.CreateInsertCommand(o);
			object id=this.ExecuteScalar(cmd,ref result);
			cmd.Dispose();
			try{
				o.TinhThanh_ID=int.Parse(Convert.ToString(id));
			}
			catch{}
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: SaveList</para>
		/// <para>Input: List of TinhThanhEntity</para>
		/// <para>Output: </para>
		///</summary>
		public void SaveList(List<TinhThanhEntity>list){
			foreach(TinhThanhEntity o in list){
				try{
					this.Save(o);
				}
				catch{
				}
			}
		}
		#endregion

		#region Update functions
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: CreateUpdateCommand</para>
		/// <para>Input: TinhThanhEntity</para>
		/// <para>Output: </para>
		///</summary>
		protected IDbCommand CreateUpdateCommand(TinhThanhEntity o){
			string strSQL="UPDATE  [TinhThanh] SET [TinhThanh].[MaTinhThanh]=@MaTinhThanh,[TinhThanh].[TenTinhThanh]=@TenTinhThanh,[TinhThanh].[GhiChu]=@GhiChu,[TinhThanh].[QuocGia_ID]=@QuocGia_ID WHERE [TinhThanh].[TinhThanh_ID]=@TinhThanh_ID";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			if(o.IsNullTinhThanh_ID)
				this.CreateCommandParameter(cmd,"@TinhThanh_ID",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@TinhThanh_ID",o.TinhThanh_ID);

			if(o.IsNullMaTinhThanh)
				this.CreateCommandParameter(cmd,"@MaTinhThanh",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@MaTinhThanh",o.MaTinhThanh);

			if(o.IsNullTenTinhThanh)
				this.CreateCommandParameter(cmd,"@TenTinhThanh",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@TenTinhThanh",o.TenTinhThanh);

			if(o.IsNullGhiChu)
				this.CreateCommandParameter(cmd,"@GhiChu",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@GhiChu",o.GhiChu);

			if(o.IsNullQuocGia_ID)
				this.CreateCommandParameter(cmd,"@QuocGia_ID",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@QuocGia_ID",o.QuocGia_ID);


			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: CreateUpdateFieldCommand</para>
		/// <para>Input: ColumnName,ColumnValue,TinhThanh_ID</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateUpdateFieldCommand(string ColumnName,object Value,int TinhThanh_ID){
			string strSQL="UPDATE  [TinhThanh] SET [TinhThanh].["+ColumnName+"]=@ColumnName WHERE [TinhThanh].[TinhThanh_ID]=@TinhThanh_ID";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@TinhThanh_ID",TinhThanh_ID);



			this.CreateCommandParameter(cmd,"@ColumnName",Value);


			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: Update</para>
		/// <para>Input: TinhThanhEntity</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool Update(TinhThanhEntity o){
			IDbCommand cmd=this.CreateUpdateCommand(o);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: UpdateList</para>
		/// <para>Input: List of TinhThanhEntity</para>
		/// <para>Output: </para>
		///</summary>
		public void UpdateList(List<TinhThanhEntity>list){
			foreach(TinhThanhEntity o in list){
				try{
					this.Update(o);
				}
				catch{
				}
			}
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: UpdateMaTinhThanh</para>
		/// <para>Input: NewMaTinhThanh,TinhThanh_ID</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool UpdateMaTinhThanh(string NewMaTinhThanh,int TinhThanh_ID){
			IDbCommand cmd=this.CreateUpdateFieldCommand("MaTinhThanh",NewMaTinhThanh,TinhThanh_ID);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: UpdateTenTinhThanh</para>
		/// <para>Input: NewTenTinhThanh,TinhThanh_ID</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool UpdateTenTinhThanh(string NewTenTinhThanh,int TinhThanh_ID){
			IDbCommand cmd=this.CreateUpdateFieldCommand("TenTinhThanh",NewTenTinhThanh,TinhThanh_ID);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: UpdateGhiChu</para>
		/// <para>Input: NewGhiChu,TinhThanh_ID</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool UpdateGhiChu(string NewGhiChu,int TinhThanh_ID){
			IDbCommand cmd=this.CreateUpdateFieldCommand("GhiChu",NewGhiChu,TinhThanh_ID);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: UpdateQuocGia_ID</para>
		/// <para>Input: NewQuocGia_ID,TinhThanh_ID</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool UpdateQuocGia_ID(int NewQuocGia_ID,int TinhThanh_ID){
			IDbCommand cmd=this.CreateUpdateFieldCommand("QuocGia_ID",NewQuocGia_ID,TinhThanh_ID);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		#endregion

		#region Delete functions
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: DeleteAllCommand</para>
		/// <para>Input: </para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateDeleteAllCommand(){
			string strSQL="DELETE   FROM [TinhThanh]  ";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: DeleteCommand</para>
		/// <para>Input: TinhThanhEntity</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateDeleteCommand(TinhThanhEntity o){
			string strSQL="DELETE   FROM [TinhThanh]   WHERE [TinhThanh].[TinhThanh_ID]=@TinhThanh_ID";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			if(o.IsNullTinhThanh_ID)
				this.CreateCommandParameter(cmd,"@TinhThanh_ID",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@TinhThanh_ID",o.TinhThanh_ID);


			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: DeleteAll</para>
		/// <para>Input: </para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool DeleteAll(){
			IDbCommand cmd=this.CreateDeleteAllCommand();
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: CreateDeleteByPrimaryKeyCommand</para>
		/// <para>Input: TinhThanh_ID</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateDeleteByPrimaryKeyCommand(int TinhThanh_ID){
			string strSQL="DELETE   FROM [TinhThanh]   WHERE [TinhThanh].[TinhThanh_ID]=@TinhThanh_ID";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@TinhThanh_ID",TinhThanh_ID);



			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: CreateDeleteByKeyCommand</para>
		/// <para>Input: ColumnName , ColumnValue</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateDeleteByKeyCommand(string ColumnName,object Value){
			string strSQL="DELETE   FROM [TinhThanh]   WHERE [TinhThanh].["+ColumnName+"]=@ColumnName";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@ColumnName",Value);



			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: Delete</para>
		/// <para>Input: TinhThanhEntity</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool Delete(TinhThanhEntity o){
			IDbCommand cmd=this.CreateDeleteCommand(o);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: DeleteByID</para>
		/// <para>Input: TinhThanh_ID</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool DeleteByID(int TinhThanh_ID){
			IDbCommand cmd=this.CreateDeleteByPrimaryKeyCommand(TinhThanh_ID);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		#endregion

		#region Select join to QuocGia functions
		#endregion

		#region Select,delete by TinhThanh_ID functions
		#endregion

		#region Select,delete by QuocGia_ID functions
		#endregion

		#region MapObject functions
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: MapObject</para>
		/// <para>Input: IDataReader</para>
		/// <para>Output: TinhThanhEntity</para>
		///</summary>
		protected override TinhThanhEntity MapObject(IDataReader r){
			TinhThanhEntity entity = new TinhThanhEntity();
			try{
				if(r.FieldCount>0){
					try
					{
						int ordinal = r.GetOrdinal("TinhThanh_ID");
						if (!r.IsDBNull(ordinal)) entity.TinhThanh_ID = ((int)(r.GetValue(ordinal)));
					}
					catch{}
					try
					{
						int ordinal = r.GetOrdinal("MaTinhThanh");
						if (!r.IsDBNull(ordinal)) entity.MaTinhThanh = ((string)(r.GetValue(ordinal)));
					}
					catch{}
					try
					{
						int ordinal = r.GetOrdinal("TenTinhThanh");
						if (!r.IsDBNull(ordinal)) entity.TenTinhThanh = ((string)(r.GetValue(ordinal)));
					}
					catch{}
					try
					{
						int ordinal = r.GetOrdinal("GhiChu");
						if (!r.IsDBNull(ordinal)) entity.GhiChu = ((string)(r.GetValue(ordinal)));
					}
					catch{}
					try
					{
						int ordinal = r.GetOrdinal("QuocGia_ID");
						if (!r.IsDBNull(ordinal)) entity.QuocGia_ID = ((int)(r.GetValue(ordinal)));
					}
					catch{}
					return entity;
				}
			}catch{}
			return null;
		}
		#endregion
	}
	/*****************************************************************************************************/
	/**********************************END TinhThanhDAOBase*****************************************/
	/*****************************************************************************************************/
}

